<?php
session_start();
if (isset($_SESSION["username"])) {
?>
  <?php require_once('common/header.php'); ?>
  <!--页面主要内容-->
  <main class="lyear-layout-content">
    <div class="container-fluid">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-toolbar clearfix">
              
              <div class="toolbar-btn-action">
                     <!--弹窗开始-->
         
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo"><i class="mdi mdi-plus"></i>添加分组</button>
                <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                  <div class="modal-dialog" role="document">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">添加分组</h4>
                      </div>
                      <div class="modal-body">
                        <form action="controller/Addgroup.php" method="post">
                          <div class="form-group">
                            <label for="group_name" class="control-label">代理等级：</label>
                            <input type="text" class="form-control" id="group_name" name="group_name" placeholder="输入代理等级">
                          </div>
                          
                          <div class="form-group">
                            <label for="group_portion" class="control-label">扣除金额：<p style="color:red;">假设100元，想让代理只拿80的佣金则填写20</p></label>
                            <input type="text" class="form-control" id="group_portion" name="group_portion" placeholder="一级代理请设置100，因为数据是以代理佣金计算，一级代理平台已扣部分金额">
                          </div>
                         
                          <!--时间戳-->
                          <input type="hidden" name="group_crtime" value="<?php echo time(); ?>">
                          <input type="hidden" name="group_uptime" value="<?php echo time(); ?>">

                      </div>
                      <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">提交</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                      </div>
                        </form>
                    </div>
                  </div>
                </div>
                <!--这是弹窗结束-->
              </div>
            </div>
            <div class="card-body">
              <div class="table-responsive">
                <form name="form1" id="form1" method="post" action="controller/doSort.php">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>组ID</th>
                        <th>名称</th>
                        <th>扣除金额</th>
                        <th>创建时间</th>
                        <th>修改时间</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                   <tbody>
                      <?php
                        include_once("../untils/conn.php");
                        mysqli_query($con, "set names utf8");
                        
                        if ($con && $db) {
                          // 获取数据总行数
                          $sortsql = "SELECT * FROM  proxy_group";
                          $sortdata = mysqli_query($con, $sortsql);
                          
                          while ($sortrow = mysqli_fetch_array($sortdata)) {
                      ?>
                            <tr>
                              <td><?php echo $sortrow["group_id"] ?></td>
                              <td><?php echo $sortrow["group_name"] ?></td>
                              <td>￥<?php echo $sortrow["group_portion"] ?></td>
                              <td><?php echo date("Y-m-d H:i:s", $sortrow["group_crtime"]) ?></td>
                              <td><?php echo date("Y-m-d H:i:s", $sortrow["group_uptime"]); ?></td>
                              <td>
                                <a class="btn btn-success btn-sm" href="upGroup.php?group_id=<?php echo $sortrow['group_id'] ?>">修改</a>
                                <a class="btn btn-danger btn-sm" href="controller/deGroup.php?group_id=<?php echo $sortrow['group_id'] ?>" onclick="return del()">删除</a>
                              </td>
                            </tr>
                      <?php
                          }
                        }
                      ?>
                    </tbody>

                  </table>
                </form>
              </div>
            </div>
          </div>
        </div>

      </div>
      <script language="javascript">
        //删除弹出确认框
        function del() {
          if (confirm("确认删除吗？")) {
            return true;
          } else {
            return false;
          }
        }

        function chek() {
          var leng = this.form1.chk.length;
          if (leng == undefined) {
            leng = 1;
            if (!form1.chk.checked)
              document.chk.checked = true;
            else
              document.form1.chk.checked = false;
          } else {
            for (var i = 0; i < leng; i++) {
              if (!form1.chk[i].checked)
                document.form1.chk[i].checked = true;
              else
                document.form1.chk[i].checked = false;
            }
          }
          return false;
        }
      </script>
    </div>
  </main>
  <!--End 页面主要内容-->
  <?php require_once('common/footer.php'); ?>
<?php
} else {
  echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
?>